package com.itheima.controller;

import com.itheima.common.PageResult;
import com.itheima.common.R;
import com.itheima.common.ResultData;
import com.itheima.domain.PmsProduct;
import com.itheima.manager.PmsProductManager;
import com.itheima.vo.PmsProductResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@CrossOrigin(origins = "*")
public class PmsProductController {
    @Autowired
    PmsProductManager pmsProductManager;

    //查询商品
    @GetMapping("/product/list")
    public ResultData list(Integer brandId, String keyword, Integer pageNum, Integer pageSize, Integer productCategoryId, String productSn, Integer publishStatus, Integer verifyStatus) {
        PageResult pageResult = pmsProductManager.list(brandId, keyword, pageNum, pageSize, productCategoryId, productSn, publishStatus, verifyStatus);
        return ResultData.ok(pageResult, "");
    }

    //根据商品名称或货号模糊查询
    @GetMapping("/product/simpleList")
    public ResultData simpleList(Integer brandId, String keyword, Integer pageNum, Integer pageSize) {
        PageResult pageResult = pmsProductManager.list(brandId, keyword, pageNum, pageSize, null, null, null, null);
        return ResultData.ok(pageResult, "");
    }

    //根据商品id获取商品编辑信息
    @GetMapping("/product/updateInfo/{id}")
    public ResultData selectById(@PathVariable Integer id) {
        PmsProduct pmsProduct = pmsProductManager.selectById(id);
        return ResultData.ok(pmsProduct, "");
    }

    //批量修改删除状态
    @PostMapping("/product/update/deleteStatus")
    public ResultData deleteStatus(@RequestParam("ids") ArrayList<Integer> ids,  Integer deleteStatus) {
        pmsProductManager.deleteStatus(ids, deleteStatus);
        return ResultData.ok(null, "");
    }

    //批量设为新品
    @PostMapping("/product/update/newStatus")
    public ResultData newStatus(@RequestParam("ids") ArrayList<Integer> ids,  Integer newStatus) {
        pmsProductManager.newStatus(ids, newStatus);
        return ResultData.ok(null, "");
    }

    //批量上下架商品
    @PostMapping("/product/update/publishStatus")
    public ResultData publishStatus(@RequestParam("ids") ArrayList<Integer> ids,  Integer publishStatus) {
        pmsProductManager.publishStatus(ids, publishStatus);
        return ResultData.ok(null, "");
    }

    //批量推荐商品
    @PostMapping("/product/update/recommendStatus")
    public ResultData recommendStatus(@RequestParam("ids") ArrayList<Integer> ids,  Integer recommendStatus) {
        pmsProductManager.recommendStatus(ids, recommendStatus);
        return ResultData.ok(null, "");
    }

    //创建商品
    @PostMapping("/product/create")
    public ResultData create(@RequestBody PmsProductResult pmsProductVo) {
        pmsProductManager.create(pmsProductVo);
        return ResultData.ok(null, "");
    }
}
